/**
 * 
 */
package ao.com.bna.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author dfancone
 * 
 */

@Entity
@Table(name = "Requisicao")
public class Requisicao implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "REQUISICAO_ID_GENERATOR", sequenceName = "REQUISICAO_SEQ", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "REQUISICAO_ID_GENERATOR")
	@Column(nullable = false, precision = 6)
	private Long id;

	@Column(length = 20)
	private String numeroDocumento;

	@Column(length = 20)
	private String mesReferente;

	@Temporal(TemporalType.DATE)
	private Date dataRegisto;

	@Temporal(TemporalType.DATE)
	private Date dataAlteracao;

	@Column(length = 200)
	private String observacao;

	// associação bi-direccional many-to-one
	@ManyToOne
	@JoinColumn(name = "idStatusRequisicao", referencedColumnName = "id", nullable = false)
	private StatusRequisicao statusRequisicao = new StatusRequisicao();

	// associação bi-direccional one-to-many
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "requisicao")
	private List<ItemRequisicao> itemRequisicoes = new ArrayList<ItemRequisicao>();

	/**
	 * 
	 */
	public Requisicao() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the numeroDocumento
	 */
	public String getNumeroDocumento() {
		return numeroDocumento;
	}

	/**
	 * @param numeroDocumento
	 *            the numeroDocumento to set
	 */
	public void setNumeroDocumento(String numeroDocumento) {
		this.numeroDocumento = numeroDocumento;
	}

	/**
	 * @return the mesReferente
	 */
	public String getMesReferente() {
		return mesReferente;
	}

	/**
	 * @param mesReferente
	 *            the mesReferente to set
	 */
	public void setMesReferente(String mesReferente) {
		this.mesReferente = mesReferente;
	}

	/**
	 * @return the dataRegisto
	 */
	public Date getDataRegisto() {
		return dataRegisto;
	}

	/**
	 * @param dataRegisto
	 *            the dataRegisto to set
	 */
	public void setDataRegisto(Date dataRegisto) {
		this.dataRegisto = dataRegisto;
	}

	/**
	 * @return the dataAlteracao
	 */
	public Date getDataAlteracao() {
		return dataAlteracao;
	}

	/**
	 * @param dataAlteracao
	 *            the dataAlteracao to set
	 */
	public void setDataAlteracao(Date dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}

	/**
	 * @return the observacao
	 */
	public String getObservacao() {
		return observacao;
	}

	/**
	 * @param observacao
	 *            the observacao to set
	 */
	public void setObservacao(String observacao) {
		this.observacao = observacao;
	}

	/**
	 * @return the statusRequisicao
	 */
	public StatusRequisicao getStatusRequisicao() {
		return statusRequisicao;
	}

	/**
	 * @param statusRequisicao
	 *            the statusRequisicao to set
	 */
	public void setStatusRequisicao(StatusRequisicao statusRequisicao) {
		this.statusRequisicao = statusRequisicao;
	}

	/**
	 * @return the itemRequisicoes
	 */
	public List<ItemRequisicao> getItemRequisicoes() {
		return itemRequisicoes;
	}

	/**
	 * @param itemRequisicoes
	 *            the itemRequisicoes to set
	 */
	public void setItemRequisicoes(List<ItemRequisicao> itemRequisicoes) {
		this.itemRequisicoes = itemRequisicoes;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Requisicao other = (Requisicao) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return numeroDocumento + " - " + mesReferente;
	}

}